package com.gxust.service.impl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxust.pojo.PageBean;
import com.gxust.pojo.Product;
import com.gxust.mapper.ProductMapper;
import com.gxust.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

@Service
public class ProductServiceImpl implements ProductService {
    private static final Logger logger = LoggerFactory.getLogger(ProductServiceImpl.class);

    @Autowired
    private ProductMapper productMapper;

    @Override
    public List<Product> list() {
        return productMapper.mallList();
    }

    @Override
    public void add(Product product,Integer id) {
        product.setSellerId(id);
        productMapper.insert(product);
    }

    @Override
    public void del(Product product) {
        productMapper.del(product);
    }

    @Override
    public void update(Product product) {
        productMapper.update(product);
    }

    @Override
    @Transactional // 开启事务管理
    public PageBean page(Integer page, Integer pageSize,Integer id) {
        //1. 设置分页参数
        PageHelper.startPage(page, pageSize);

        //2. 执行查询
        List< Product> productList = productMapper.list(id);
        Page<Product> p = (Page<Product>) productList;

        //3. 封装PageBean对象
        return new PageBean(p.getTotal(), p.getResult());
    }

    @Override
    public Product ProductInfoById(Integer id) {
        return productMapper.productbyid(id);
    }

    @Override
    public List<Product> mallList() {
        return productMapper.mallListHot();
    }

    @Override
    public List<Product> mallListSelect() {
        return productMapper.mallListSelect();
    }

    @Override
    public List<Product> ProductBySellerId(Integer id) {
        return productMapper.ProductBySellerId(id);
    }


}
